Page 3 of 3 FirstFirst 123
Results 21 to 25 of 25

Thread: How to know when a player is walking/running?

  1. #21
    Client Beta Testers Appelpitje's Avatar
    Join Date
    Jan 2012
    Location
    Belgium
    Posts
    545

    Default

    Quote Originally Posted by Sor View Post
    Ah yeah, forgot to put a wait in there, one second should do.

    You still have to reverse the changes when the player is not standing, or leaning will remain disabled.
    Yes indeed, the wait did the trick

    What do you mean by reversing the changes? Its indeed now no leaning while running, standing, crouching.

    Also the server crashes when you leave the server:
    Code:
    im crouching
    broadcast: print "G|u|N-Appelpitje|ƒ!A| disconnected\n"
    Going to CS_ZOMBIE for G|u|N-Appelpitje|ƒ!A|
                    if ($player[local.i].nolean == NIL) { (global/nolean3.scr, 8)
                    if ($player[local.i]^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    
          local.player.nolean = 1 (global/nolean3.scr, 16)
          local.player^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    
               for (local.i = 1; local.i <= $player.size; local.i++) { (global/nolean3.scr, 6)
               for (local.i = 1; local^
    
    ********************
    ERROR: Command overflow.  Possible infinite loop in thread.
    
    ********************

  2. #22
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Where did you put the wait?
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  3. #23
    Client Beta Testers Appelpitje's Avatar
    Join Date
    Jan 2012
    Location
    Belgium
    Posts
    545

    Default

    main:
    while !($player)
    wait 1

    while(1) {
    for (local.i = 1; local.i <= $player.size; local.i++) {
    wait 1
    if ($player[local.i].nolean == NIL) {
    thread nolean $player[local.i]
    }
    }
    }
    end

    Error in console:
    Code:
    Going to CS_ZOMBIE for G|u|N-Appelpitje|ƒ!A|
                    if ($player[local.i].nolean == NIL) { (global/nolean3.scr, 9)
                    if ($player[local.i]^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    
          local.player.nolean = 1 (global/nolean3.scr, 18)
          local.player^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    
                    if ($player[local.i].nolean == NIL) { (global/nolean3.scr, 9)
                    if ($player[local.i]^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    
          local.player.nolean = 1 (global/nolean3.scr, 18)
          local.player^
    
    ^~^~^ Script Error: Field 'nolean' applied to NULL listener
    Also, how do i disable lean when the player is crouching? Its tottaly disabled now
    I think if have to put something in the else function? I tried this:
    Code:
    nolean local.player:
          local.player.nolean = 1
          while (local.player) {
    		local.position = local.player getposition
                if (local.position == "crouching") {
    				 println "im crouching"
                     local.player stufftext "+leanleft;+leanright"
    				 wait 0.3
    			}
                else {
    			local.player stufftext "-leanleft;-leanright"
    				wait 0.3
                }
           }
    end
    But then the player has shocking leaning, im not sure how to just disable the +leanright and +leanleft
    Last edited by Appelpitje; May 16th, 2013 at 06:25 AM.

  4. #24
    Developer Sor's Avatar
    Join Date
    Aug 2010
    Location
    The Medieval City of Bruges
    Posts
    747

    Default

    Quote Originally Posted by Appelpitje View Post
    main:
    while !($player)
    wait 1

    while(1) {
    for (local.i = 1; local.i <= $player.size; local.i++) {
    wait 1
    if ($player[local.i].nolean == NIL) {
    thread nolean $player[local.i]
    }
    }
    }
    end
    Wait should almost always go in the outer loop, especially if that one is an infinite while() loop. In this case,
    if there are no players on the server, the for() loop with the wait is never run and the outer loop goes nuts.

    Quote Originally Posted by Appelpitje View Post
    Also, how do i disable lean when the player is crouching? Its tottaly disabled now
    I think if have to put something in the else function? I tried this:
    Code:
    nolean local.player:
          local.player.nolean = 1
          while (local.player) {
            local.position = local.player getposition
                if (local.position == "crouching") {
                     println "im crouching"
                     local.player stufftext "+leanleft;+leanright"
                     wait 0.3
                }
                else {
                local.player stufftext "-leanleft;-leanright"
                    wait 0.3
                }
           }
    end
    But then the player has shocking leaning, im not sure how to just disable the +leanright and +leanleft
    That's what I've been saying. What you're doing now, is falsely assuming that every player who isn't crouching, has just stopped crouching
    and needs their leaning re-enabled. Likewise, but less directly noticeable, you are assuming that when a player is crouching, he just started
    crouching and thus needs leaning disabled. Perhaps that was the intention, preventing the player from re-enabling leaning himself; but
    the sheer number of stufftexts you do in order to prevent this from happening is unwarranted.

    What we need is a way to make a distinction between players. When a player is crouching, we disable leaning and we need to prevent this
    from repeating for as long as the player is crouching. When a player is standing, we re-enable leaning but we need to prevent this for any
    player who can lean. In order to do this we add a new property to the player entities and use it a 'flag' to indicate in which state the player
    is. This 'state' will only be relevant for this algorithm. So it would look something like this:

    Code:
    nolean local.player:
          local.player.nolean = 1
          local.player.canLean  = 1
          
          while (local.player) {
            if (local.player.canLean && (local.player getposition)[0] == "c") {
                println "im crouching"
                local.player stufftext "+leanleft;+leanright"
                local.player.canLean = 0
            }
            else if (!local.player.canLean && (local.player getposition)[0] == "s") {
                local.player stufftext "-leanleft;-leanright"
                local.player.canLean = 1;
            }
            wait 0.3
        }
    end
    Here if a player is crouching and canLean (==1, but I'm evaluating as boolean and 1 is true), his leaning is disabled and .canLean is set to 0 (false) so it
    won't enter this if() statement as long as that flag remains 0. Likewise, if canLean is 0 but the player is standing, then he needs to be able to lean again.

    However, I'm not a fan of 'flag control', especially their overuse. If I can avoid it, I will. Nonetheless, they remain very useful.
    But we're doing 3 comparisons too many (every 0.3 sec) when, after all, we only need to act when a player is crouching, right?
    Also, we have the additional problem that if the player is savvy enough, he can re-enable leaning himself.

    I prefer:
    Code:
    nolean local.player:
          local.player.nolean = 1
          local.player.canLean  = 1
          
          while (local.player) {
            if ((local.player getposition)[0] == "c") {
                println "im crouching"
                local.player.canLean  = 0
                
                local.player waitthread cannotlean
                if (!local.player) 
                    break
                    
                local.player stufftext "-leanleft;-leanright"
                local.player.canLean  = 1;
            }
            wait 0.3
        }
    end
    
    cannotlean:
        while(self && (self getposition)[0] == "c") {
            self stufftext "+leanleft;+leanright"
            wait 1
        }
    end;
    Here, .canLean has ceased to be a flag and now acts like a property alone that other modders can check in their scripts. We only check if a player is crouching;
    if he is, we set our property accordingly and then we freeze this loop using a 'waitthread' to call 'cannotlean'. The player entity initiated the execution so he is 'self'.
    In that thread, we enforce no-lean as long as this player is crouching. One second should be fine, even if the player has binded a key to enable leaning, he'd have to
    press it every second. As you can imagine, he won't keep it up.

    The side-effect is that it may take up to one second after the player stopped crouching before leaning is on again; so you can tighten that loop if necessary.
    Anyway, that loop will break and that thread will end when the player stops crouching or leaves the server. We need to check the latter again in our other
    loop before continuing or errors will occur. After that, we can safely assume that the player is not crouching and had his leaning disabled so we can undo this.

    I hope this helps;
    and I hope I didn't forget something or made a typo this time because I haven't tested it.
    Last edited by Sor; May 16th, 2013 at 03:47 PM.
    Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.

  5. #25
    Client Beta Testers Appelpitje's Avatar
    Join Date
    Jan 2012
    Location
    Belgium
    Posts
    545

    Default

    Thank you very much Sor, you made some things clear to me!

    And it does work very well without errors!

Page 3 of 3 FirstFirst 123

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •